import axios from 'axios'
import settings from '../settings'
var baseUrl = settings.target
export function upload(data) {
  return new Promise((resolve, reject) => {
    const formData = new FormData()
    formData.append('file', data)
    axios({
      url: `${baseUrl}/file/upload`,
      method: 'post',
      headers: {
        'content-type': 'multipart/form-data',
        'token': localStorage.getItem('token')
      },
      data: {
        file: data.file
      }
    }).then(res => {
      console.log(res)
      const data = res.data
      const code = data.code
      if (code === 200) {
        resolve(res)
      } else {
        console.log(data.message)
        reject(data.message)
      }
    })
  })
}
